from typing import List


class Solution:
    def isValidSudoku(self, board: List[List[str]]) -> bool:
        row = [[0] * 9 for _ in range(9)]
        col = [[0] * 9 for _ in range(9)]
        box = [[0] * 9 for _ in range(9)]

        for i in range(9):
            for j in range(9):
                if board[i][j] == '.': continue
                
                num = int(board[i][j]) - 1
                if row[i][num]: return False
                if col[j][num]: return False
                if box[(i//3)*3+(j//3)][num]: return False

                row[i][num] = 1
                col[j][num] = 1
                box[(i//3)*3+(j//3)][num] = 1

        return True


if __name__ == "__main__":
    so = Solution()
    sudoku = [["8","3",".",".","7",".",".",".","."],["6",".",".","1","9","5",".",".","."],[".","9","8",".",".",".",".","6","."],["8",".",".",".","6",".",".",".","3"],["4",".",".","8",".","3",".",".","1"],["7",".",".",".","2",".",".",".","6"],[".","6",".",".",".",".","2","8","."],[".",".",".","4","1","9",".",".","5"],[".",".",".",".","8",".",".","7","9"]]
    print(so.isValidSudoku(sudoku))
